﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

    internal class AccDataReader
    {
        /*
         * // NOG VERBETEREN //
         * ////////////////////
        public static ListViewItem readAccountData(string File)
        {
            StreamReader reader = new StreamReader(File);
            string line, key;
            int amountAccounts = countAccounts(File);
            string[] usernames = new string[amountAccounts], passwords = new string[amountAccounts];
            int countUsernames = 0, countPasswords = 0;
            do
            {
                line = reader.ReadLine();
                if (line.StartsWith("#") == false)
                {
                    
                    
                        //getUsernames();

                                
                }
            }
            while (reader.EndOfStream != true);
            
            return new ListViewItem(usernames);
        }
         * */ 

        public static string[] getPasswords(string File, int Accounts)
        {
            //string key = getKey(File);
            using (StreamReader reader = new StreamReader(File))
            {
                string[] passwords = new string[Accounts];
                int count = 0;
                do
                {
                    string line = reader.ReadLine();
                    if (line.StartsWith("<pass>"))
                    {
                        line = line.Replace("<pass>", null);
                        line = line.Replace("</pass>", null);
                        //line = StringCrypt.Vigenere(line, Regex.Replace(key, @"\d", ""), 94, true);
                        passwords[count] = line;
                        count++;
                    }
                } while (reader.EndOfStream != true);
                return passwords;
            }            
        }

        public static string[] getUsernames(string File, int Accounts)
        {
            using (StreamReader reader = new StreamReader(File))
            {
                string[] usernames = new string[Accounts];
                int count = 0;
                do
                {
                    string line = reader.ReadLine();
                    if (line.StartsWith("<usrname>"))
                    {
                        line = line.Replace("<usrname>", null);
                        line = line.Replace("</usrname>", null);
                        usernames[count] = line;
                        count++;
                    }
                } while (reader.EndOfStream != true);
                return usernames;
            }
        }

        public static string getKey(string File)
        {
            using (StreamReader reader = new StreamReader(File))
            {
                string line = "";
                do
                {
                    line = reader.ReadLine();
                    if (line.StartsWith("<key>"))
                    {
                        line = line.Replace("<key>", "");
                        line = line.Replace("</key>", "");
                    }
                }
                while (reader.EndOfStream != true);
                return line;
            }
        }


        public static int countAccounts(string File)
        {
            using (StreamReader reader = new StreamReader(File))
            {
                int count = 0;
                do
                {
                    string line = reader.ReadLine();
                    if (line.StartsWith("<usrname>"))
                    {
                        count += 1;
                    }
                } while (reader.EndOfStream != true);
                return count;
            }
        }
    }
